// pages/order/studentinfo/studentinfo.js
const App = getApp()

let { imgUrl } = require("../../../utils/util.js")
Page({

  /**
   * 页面的初始数据
   */
  data: {
    navH:'',
    student:{
      customer_name: '',
      sex: 1,
      age: '',    
      card: '',
      father_mobile: '',
      mother_mobile: ''
    },
    index:''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      navH: App.globalData.navHeight
    })
    if (wx.getStorageSync("studentedit")){
      this.setData({
        student: JSON.parse(wx.getStorageSync("studentedit")).list,
        index: JSON.parse(wx.getStorageSync("studentedit")).index
      })
    }
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  navBack(){
    wx.removeStorageSync('student')
    wx.removeStorageSync('studentedit')
    wx.navigateBack()
  },
  inputInfo(e){
    let _type  = e.currentTarget.dataset.type
    let _data = this.data.student
    _data[_type] = e.detail.value
    this.setData({
      'student': _data
    })
  },
  selectSex(e){
    let _val = e.currentTarget.dataset.val
    this.setData({
      'student.sex':_val
    })
  },
  sureStudent(){
    let vm =this
    if (!vm.data.student.customer_name){
      wx.showToast({
        title: '请输入您的姓名',
        icon:"none"
      })
      return
    }
    let _obj = {
      index:'add',
      list: vm.data.student
    }
    if (wx.getStorageSync("studentedit")){
      _obj.index = vm.data.index
    }
    wx.setStorageSync("student", JSON.stringify(_obj))
    wx.removeStorageSync('studentedit')
    wx.navigateBack()
  }
})